
/*
* ProductsDAL
*/
using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;

using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Carmall.Entity;
using Carmall.IDAL;

namespace Carmall.DAL
{
	/// <summary>
	/// Products DAL 的摘要说明。
	/// </summary>
	public class Products : BaseDAL<ProductsInfo>, IProducts
	{
		#region 对象实例及构造函数

		public static Products Instance
		{
			get
			{
				return new Products();
			}
		}
		public Products() : base("products","ProductID")
		{
		}

		#endregion

		/// <summary>
		/// 将DataReader的属性值转化为实体类的属性值，返回实体类
		/// </summary>
		/// <param name="dr">有效的DataReader对象</param>
		/// <returns>实体类对象</returns>
		protected override ProductsInfo DataReaderToEntity(IDataReader dataReader)
		{
			ProductsInfo productsInfo = new ProductsInfo();
			SmartDataReader reader = new SmartDataReader(dataReader);
			
			
			productsInfo.ProductID = reader.GetInt32("ProductID");
			productsInfo.Name = reader.GetString("Name");
			productsInfo.ShorName = reader.GetString("ShorName");
			productsInfo.Code = reader.GetString("Code");
			productsInfo.Category = reader.GetInt32("Category");
			productsInfo.CategoryName = reader.GetString("CategoryName");
			productsInfo.Brand = reader.GetInt32("Brand");
            productsInfo.Price = reader.GetDecimal("Price");
			productsInfo.Quantity = reader.GetInt32("Quantity");
			productsInfo.Color = reader.GetString("Color");
			productsInfo.SuitableModel = reader.GetString("SuitableModel");
			productsInfo.Specification = reader.GetString("Specification");
			productsInfo.Supplier = reader.GetInt32("Supplier");
			productsInfo.SupplierName = reader.GetString("SupplierName");
			productsInfo.Place = reader.GetString("Place");
			productsInfo.ZhibaoXieyi = reader.GetString("ZhibaoXieyi");
			productsInfo.Baozhiqi = reader.GetString("Baozhiqi");
			productsInfo.Face = reader.GetString("Face");
			productsInfo.Chemian = reader.GetString("Chemian");
			productsInfo.Jeikou = reader.GetString("Jeikou");
			productsInfo.Install = reader.GetString("Install");
			productsInfo.Display = reader.GetInt32("Display");

			
			return productsInfo;
		}

		/// <summary>
		/// 将实体对象的属性值转化为Hashtable对应的键值
		/// </summary>
		/// <param name="obj">有效的实体对象</param>
		/// <returns>包含键值映射的Hashtable</returns>
		protected override Hashtable GetHashByEntity(ProductsInfo obj)
		{
			ProductsInfo info = obj as ProductsInfo;
			Hashtable hash = new Hashtable(); 
			
			
			hash.Add("ProductID", TypeHelper.SafeInt(info.ProductID));
			hash.Add("Name", TypeHelper.SafeString(info.Name));
			hash.Add("ShorName", TypeHelper.SafeString(info.ShorName));
			hash.Add("Code", TypeHelper.SafeString(info.Code));
			hash.Add("Category", TypeHelper.SafeInt(info.Category));
			hash.Add("CategoryName", TypeHelper.SafeString(info.CategoryName));
			hash.Add("Brand", TypeHelper.SafeInt(info.Brand));
            hash.Add("Price", TypeHelper.SafeDecimal(info.Price));
			hash.Add("Quantity", TypeHelper.SafeInt(info.Quantity));
			hash.Add("Color", TypeHelper.SafeString(info.Color));
			hash.Add("SuitableModel", TypeHelper.SafeString(info.SuitableModel));
			hash.Add("Specification", TypeHelper.SafeString(info.Specification));
			hash.Add("Supplier", TypeHelper.SafeInt(info.Supplier));
			hash.Add("SupplierName", TypeHelper.SafeString(info.SupplierName));
			hash.Add("Place", TypeHelper.SafeString(info.Place));
			hash.Add("ZhibaoXieyi", TypeHelper.SafeString(info.ZhibaoXieyi));
			hash.Add("Baozhiqi", TypeHelper.SafeString(info.Baozhiqi));
			hash.Add("Face", TypeHelper.SafeString(info.Face));
			hash.Add("Chemian", TypeHelper.SafeString(info.Chemian));
			hash.Add("Jeikou", TypeHelper.SafeString(info.Jeikou));
			hash.Add("Install", TypeHelper.SafeString(info.Install));
			hash.Add("Display", TypeHelper.SafeInt(info.Display));

			
			return hash;
		}
	}
}
